# -*- coding: utf-8 -*-
#   Copyright (c) 2021 FromVB2Python
#   FromVB2Python is licensed under Mulan PSL v2.
#   You can use this software according to the terms and conditions of the Mulan PSL v2. 
#   You may obtain a copy of Mulan PSL v2 at:
#            http://license.coscl.org.cn/MulanPSL2 
#   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
#   See the Mulan PSL v2 for more details.  
import tkinter as tk
def myfun():
    '''按查找与统计4位数中玫瑰花数'''
    lbx.delete(0,'end')
    win.update()
    for i in range(1000,9999+1):
        lst = list(map(int,str(i)))
        tmp = 0
        for j in lst:
            tmp += j**4
        if tmp == i:
            lbx.insert('end', i)
    lbl['text'] = '玫瑰花数个数为：{}'.format(lbx.size())

win = tk.Tk()
win.title('玫瑰花数')
lbx = tk.Listbox(win)
lbl = tk.Label(win,text='玫瑰花数个数为：', anchor='w')
can = tk.Canvas(win, height=106, width=92)
imgfile=tk.PhotoImage(file='rose.gif')  # rose.gif图片要放在同一文件夹中
img = tk.Label(can,image=imgfile)
img.place(relx=0, rely=0, relheight=1.0, relwidth=1.0)
btn = tk.Button(win, text='统计', command=myfun)

lbx.grid(row=0, column=0, rowspan=2, padx=5, pady=5)
can.grid(row=0, column=1, padx=5)
btn.grid(row=1, column=1)
lbl.grid(row=3, column=0, padx=5,pady=(0,5), sticky='we')

win.mainloop()
